package com.tcenter.dao.entities;


import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import static javax.persistence.GenerationType.IDENTITY;

/**
 *
 */
@Entity
@Table(name = "user", catalog = "tcenterdb", uniqueConstraints = {
        @UniqueConstraint(columnNames = "mobile"),
        @UniqueConstraint(columnNames = "email")})
@Inheritance(strategy = InheritanceType.JOINED)
public class User implements java.io.Serializable {

    private Integer id;
    private String firstName;
    private String secondName;
    private String email;
    private String password;
    private String secretQuestion;
    private String secretAnswer;
    private String mobile;
    private Byte gender;
    private Date birthdayDate;
    private boolean isBlocked;
    private Date registrationDate;
    private boolean isVerified;
    private boolean isDeleted;
    private Set<UserVerification> userVerifications = new HashSet<UserVerification>(0);
    private Set<UserRole> userRolesForUserId = new HashSet<UserRole>(0);
    private Set<UserRole> userRolesForGrantedBy = new HashSet<UserRole>(0);


    public User() {
    }

    public User(String firstName, String secondName) {
        this.firstName = firstName;
        this.secondName = secondName;
    }

    public User(String firstName, String secondName, String email, String password, String mobile) {
        this.firstName = firstName;
        this.secondName = secondName;
        this.email = email;
        this.password = password;
        this.mobile = mobile;
    }


    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Column(name = "first_name", nullable = false, length = 15)
    public String getFirstName() {
        return this.firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    @Column(name = "second_name", nullable = false, length = 15)
    public String getSecondName() {
        return this.secondName;
    }

    public void setSecondName(String secondName) {
        this.secondName = secondName;
    }

    @Column(name = "email", unique = true, nullable = false, length = 25)
    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Column(name = "password", nullable = false, length = 10)
    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Column(name = "secret_question", nullable = false, length = 128)
    public String getSecretQuestion() {
        return this.secretQuestion;
    }

    public void setSecretQuestion(String secretQuestion) {
        this.secretQuestion = secretQuestion;
    }

    @Column(name = "secret_answer", nullable = false, length = 128)
    public String getSecretAnswer() {
        return this.secretAnswer;
    }

    public void setSecretAnswer(String secretAnswer) {
        this.secretAnswer = secretAnswer;
    }

    @Column(name = "mobile", unique = true, nullable = false, length = 11)
    public String getMobile() {
        return this.mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    @Column(name = "gender")
    public Byte getGender() {
        return this.gender;
    }

    public void setGender(Byte gender) {
        this.gender = gender;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "birthday_date", nullable = false, length = 10)
    public Date getBirthdayDate() {
        return this.birthdayDate;
    }

    public void setBirthdayDate(Date birthdayDate) {
        this.birthdayDate = birthdayDate;
    }

    @Column(name = "is_blocked", nullable = false)
    public boolean isBlocked() {
        return this.isBlocked;
    }

    public void setBlocked(boolean isBlocked) {
        this.isBlocked = isBlocked;
    }

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "registration_date", length = 19)
    public Date getRegistrationDate() {
        return this.registrationDate;
    }

    public void setRegistrationDate(Date registrationDate) {
        this.registrationDate = registrationDate;
    }

    @Column(name = "is_verified", nullable = false)
    public boolean isVerified() {
        return this.isVerified;
    }

    public void setVerified(boolean isVerified) {
        this.isVerified = isVerified;
    }

    @Column(name = "is_deleted", nullable = false)
    public boolean isDeleted() {
        return this.isDeleted;
    }

    public void setDeleted(boolean isDeleted) {
        this.isDeleted = isDeleted;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
    public Set<UserVerification> getUserVerifications() {
        return this.userVerifications;
    }

    public void setUserVerifications(Set<UserVerification> userVerifications) {
        this.userVerifications = userVerifications;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "userByUserId")
    public Set<UserRole> getUserRolesForUserId() {
        return this.userRolesForUserId;
    }

    public void setUserRolesForUserId(Set<UserRole> userRolesForUserId) {
        this.userRolesForUserId = userRolesForUserId;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "userByGrantedBy")
    public Set<UserRole> getUserRolesForGrantedBy() {
        return this.userRolesForGrantedBy;
    }

    public void setUserRolesForGrantedBy(Set<UserRole> userRolesForGrantedBy) {
        this.userRolesForGrantedBy = userRolesForGrantedBy;
    }

}
